/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------

*/
package tests.jd.crypt;

/*
 * JDTest.java
 *
 * Created on January 7, 2003, 10:51 AM
 */

/**
 *
 * @author  jd
 */
import java.math.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;

import javax.crypto.*;

import org.bouncycastle.util.test.*;
import org.bouncycastle.util.encoders.Hex;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.crypto.params.*;
import org.bouncycastle.crypto.generators.*;
import org.bouncycastle.crypto.*;

public class JDTest {
    
    //17 in hex
    private static BigInteger pubExp = new BigInteger("65537", 10);
//65537
    /** Creates a new instance of JDTest */
    public JDTest() {
    }
    
    public static void main(String[] args) throws Exception{        
        
        //RSAKeyGenerationParameters RSAKeyGenPara = 
        //new RSAKeyGenerationParameters(pubExp, sr, 1024, 80);
                
        RSAKeyGenerationParameters RSAKeyGenPara = new RSAKeyGenerationParameters(pubExp, new SecureRandom(), 2048, 80);

        RSAKeyPairGenerator RSAKeyPairGen = new RSAKeyPairGenerator();
        RSAKeyPairGen.init(RSAKeyGenPara);
        AsymmetricCipherKeyPair keyPair = RSAKeyPairGen.generateKeyPair();
         
        RSAKeyParameters pubKey = (RSAKeyParameters) keyPair.getPublic();    
        System.out.println("PublicExponent=" + pubKey.getExponent().toString(16) );
        System.out.println("modulus=" + pubKey.getModulus().toString(16) );

        RSAKeyParameters privKey = (RSAKeyParameters) keyPair.getPrivate();
        System.out.println("PrivateExponent=" + privKey.getExponent().toString(16) );
        System.out.println("modulus=" + privKey.getModulus().toString(16) );
       
        
        
        
//java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
//javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding" ,"BC");        
        
        //Cipher c = Cipher.getInstance("RSA", "BC");
    
        //keyPairGen.initialize(
        //        new RSAKeyGenParameterSpec(768,
        //        BigInteger.valueOf(65537)),
        //        new SecureRandom());

        //KeyPair kp = keyPairGen.generateKeyPair();

        //PublicKey pubKey = keyPairp.getPublic();
        //PrivateKey privKey = kp.getPrivate();

//SecureRandom        rand = new FixedSecureRandom();
        
 //       c.init(Cipher.ENCRYPT_MODE, (Key)keyPair.getPublic(), new SecureRandom());
                
  //      byte[] out = c.doFinal("hello world".getBytes());

        //System.out.println("after encrypt =" + new String(out));
                
       // c.init(Cipher.DECRYPT_MODE, (Key)keyPair.getPrivate());

            //out = c.doFinal(out);
            
//            System.out.println("after decrypt = " + new String(out));
                        
    //java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    //javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding" ,"BC");    
      //      Cipher c = Cipher.getInstance("RSA", "BC");
        //    KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", "BC");

            //
            // 768 bit RSA with e = 2^16-1
            //
            //keyPairGen.initialize(
            //new RSAKeyGenParameterSpec(2048,
            //BigInteger.valueOf(65537)),
            //new SecureRandom());
/*
            keyPairGen.initialize(
            new RSAKeyGenParameterSpec(16,
            new BigInteger("11", 16)),
            new SecureRandom());

            KeyPair kp = keyPairGen.generateKeyPair();
            RSAPublicKey pubKey = (RSAPublicKey)kp.getPublic();
            System.out.println("public key = " + pubKey.toString());
            
            
            
            
            
            RSAPrivateKey privKey = (RSAPrivateKey)kp.getPrivate();

            System.out.println("privKey =  " + privKey.toString());
            
            
            
            
            
            c.init(Cipher.ENCRYPT_MODE, pubKey, new SecureRandom());
            
            byte[] out = c.doFinal("hello world".getBytes());
            System.out.println("after enc = " + new String(out));
            
            c.init(Cipher.DECRYPT_MODE, privKey);
            
            out = c.doFinal(out);    
            System.out.println("after dec = " + new String(out));
  */  
    }
    
}
